/** @brief File declaring a class managing the games rules.
 *
 * @author Johan "Solo" Luisier
 * @date 2014/03/17
 */
#ifndef RULEMANAGER_HPP
#define RULEMANAGER_HPP

#include <Core/RuleData.hpp>

#include <QtGui/QDialog>

class QStandardItemModel;
class QListView;

/** @brief Class providing a UI to manage the game rules.
 *
 * This class provides a user interface to manage the game rules. The internal
 * game rules are contained by a RuleData instance, this class is an interface
 * allowing the user to change them.
 *
 * @class RuleManager "RuleManager.hpp" "App/RuleManager.hpp"
 */
class RuleManager : public QDialog
{
    Q_OBJECT
public:
    /** @brief Constructor, initialises the data members.
     *
     * The constructor delegates the UI constructor to the setupGui method. The
     * connections for the context menu are made in here.
     *
     * @param[in] rules instance of RuleData to modify.
     * @param[in] parent pointer on the parent widget.
     */
    RuleManager( const RuleData& rules, QWidget* parent = 0 );
    /** @brief Destructor, @c virtual to ensure a correct destruction sequence.
     *
     * The destructor has nothing special to do.
     */
    virtual ~RuleManager();
    /** @brief Getter for Rules.
     *
     * This method allows to access Rules.
     *
     * @return a const reference on Rules.
     */
    inline const RuleData& rules() const { return Rules; }
protected:
    /** @brief Contains the rules the instance modifies.
     */
    RuleData Rules;
    /** @brief Widget showing the birth conditions.
     */
    QListView* BirthConditions;
    /** @brief Widget showing the survival conditions.
     */
    QListView* SurvivalConditions;
    /** @brief Model containing the working data for birth conditions.
     */
    QStandardItemModel* BirthModel;
    /** @brief Model containing the working data for survival conditions.
     */
    QStandardItemModel* SurvivalModel;
protected slots:
    /** @brief Slot showing the deleting menu for the birth conditions.
     *
     * This slot shows the contect menu which allows to delete the birth
     * condition which was clicked on. The given point is used to show the menu
     * at the right place and to deduce the clicked item.
     *
     * @param[in] pt point where the widget was clicked on.
     */
    void showBirthContextMenu( const QPoint& pt );
    /** @brief Slot adding a birth condition.
     *
     * This slot adds a birth condition to the model and the RuleData instance.
     * The value of the added item to add is retrieved from the triggering
     * QAction::data method.
     */
    void addBirthCondition();
    /** @brief Slot deleting a birth condition.
     *
     * This slot removes a birth condition from the model and the RuleData
     * instance. The index of the item to remove is retrieved from the
     * triggering QAction::data method.
     */
    void deleteBirthCondition();
    /** @brief Slot showing the deleting menu for the survival conditions.
     *
     * This slot shows the contect menu which allows to delete the survival
     * condition which was clicked on. The given point is used to show the menu
     * at the right place and to deduce the clicked item.
     *
     * @param[in] pt point where the widget was clicked on.
     */
    void showSurvivalContextMenu( const QPoint& pt );
    /** @brief Slot adding a survival condition.
     *
     * This slot adds a survival condition to the model and the RuleData
     * instance. The value of the added item to add is retrieved from the
     * triggering QAction::data method.
     */
    void addSurvivalCondition();
    /** @brief Slot deleting a survival condition.
     *
     * This slot removes a survival condition from the model and the RuleData
     * instance. The index of the item to remove is retrieved from the
     * triggering QAction::data method.
     */
    void deleteSurvivalCondition();
private:
    /** @brief Method setting up the GUI.
     *
     * This method creates the widget's layout. The buttons' signals are
     * connected in here.
     */
    void setupGui();
};

#endif // RULEMANAGER_HPP
